/**
 * COPYRIGHT© KMTC 2007
 * This software is the proprietary information of Korea Marine Transport Co.LTD
 * 
 * Revision History
 * Author					Date				Description
 * ------					----				-----------
 * �?주희@wees.co.kr	2007.12.14		Logging 처리�? ?��?�� Advice
 */
package kr.or.javacafe.common.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.*;

/**
 * @author mousing
 *
 */
public class LoggingAdvice implements MethodInterceptor {
	
	protected final Log logger = LogFactory.getLog(getClass());

	/* (non-Javadoc)
	 * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
	 */
	public Object invoke(MethodInvocation invocation) throws Throwable {

		String className = invocation.getThis().getClass().getName();
		
		if( logger.isDebugEnabled() ){
			logger.debug(className + "." + invocation.getMethod().getName() + "()" + " 시작!!! ");
			Object[] args = invocation.getArguments();
			if( (args != null) && (args.length > 0) ){
				for( int i=0; i < args.length; i++){
					logger.debug("Argument[" + i + "] : " + args[i]);
				}
			}
		}
		
		Object retVal = invocation.proceed();
		
		if( logger.isDebugEnabled() ){
			logger.debug(className + "." + invocation.getMethod().getName() + "()" + " 종료!!! ");
		}
		
		return retVal;
	}

}
